#include "NumOne.h"
NumOne::NumOne ()
{
	animFrames=new CCArray();
	
CCSpriteFrame* pFrame0 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_0.png");
	animFrames->addObject(pFrame0);
CCSpriteFrame* pFrame1 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_1.png");
	animFrames->addObject(pFrame1);
CCSpriteFrame* pFrame2 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_2.png");
	animFrames->addObject(pFrame2);
CCSpriteFrame* pFrame3 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_3.png");
	animFrames->addObject(pFrame3);
CCSpriteFrame* pFrame4 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_4.png");
	animFrames->addObject(pFrame4);
CCSpriteFrame* pFrame5 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_5.png");
	animFrames->addObject(pFrame5);
CCSpriteFrame* pFrame6 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_6.png");
	animFrames->addObject(pFrame6);
CCSpriteFrame* pFrame7 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_7.png");
	animFrames->addObject(pFrame7);
CCSpriteFrame* pFrame8 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_8.png");
	animFrames->addObject(pFrame8);
CCSpriteFrame* pFrame9 =CCSpriteFrameCache::sharedSpriteFrameCache()
		->spriteFrameByName("numWhite_0_9.png");
	animFrames->addObject(pFrame9);

	this->initWithSpriteFrame((CCSpriteFrame *)animFrames->objectAtIndex(0));
}
void NumOne::gotoAndStop(int i)//1 base
{
	this->initWithSpriteFrame((CCSpriteFrame *)this->animFrames->objectAtIndex(i-1));

}
NumOne::~NumOne()
{
	animFrames->release();
}
int Num::draw(int num)
{
    if (num < 10)
    {
        firstNum->gotoAndStop(num + 1);
        secondNum->gotoAndStop(1);
    }
    else
    {
        int i= num / 10;
        secondNum->gotoAndStop((i + 1));
        firstNum->gotoAndStop((num % 10 + 1));
    }
    return num;
}
Num::Num (float x1,float y1)
{
    this->setPosition(ccp(x1,y1));
    secondNum = new NumOne();secondNum->autorelease();
    firstNum = new NumOne(); firstNum->autorelease();
    firstNum->setPosition(ccp(secondNum->getContentSize().width,0));
    
    addChild(secondNum);
    addChild(firstNum);
   
    
    
    //trace(secondNum.x, secondNum.y, firstNum.x, firstNum.y);
    
}
int Num2::draw(int num)
{
    int i;//,j,k;
    
    
    if (num < 10)
    {
        fouthNum->gotoAndStop(1);
        thirdNum->gotoAndStop(1);
        secondNum->gotoAndStop(num + 1);
        firstNum->gotoAndStop(1);
    }
    else if (num < 100)
    {
        i = num / 10;
        fouthNum->gotoAndStop(1);
        thirdNum->gotoAndStop(1);
        secondNum->gotoAndStop(num % 10 + 1);
        firstNum->gotoAndStop(i+1);
    }
    return num;
}
Num2::Num2 (float x1,float y1)
{
    this->setPosition(ccp(x1,y1));
    firstNum = new NumOne();    firstNum->autorelease();
    secondNum = new NumOne();    secondNum->autorelease();
    secondNum->setPosition(ccp(firstNum->getContentSize().width,0));
    
    
    thirdNum = new NumOne();     thirdNum->autorelease();
     fouthNum = new NumOne();fouthNum->autorelease();
    //thirdNum.x = secondNum1.x + secondNum1.width
    thirdNum->setPosition(ccp(secondNum->getPosition().x+secondNum->getContentSize().width,0));
    //fouthNum.x = thirdNum.x + thirdNum.width;
    fouthNum->setPosition(ccp(thirdNum->getPosition().x+thirdNum->getContentSize().width,0));
    addChild(firstNum);
    addChild(secondNum);
    addChild(thirdNum);
    addChild(fouthNum);
    draw(0);
}
int NumX::draw(int num)
{
    //int i;//,j,k;
    //true value is num*100, so leave 00
    
    int max=pow(10,nums->count());
    num =num % max;
    int wei=nums->count();
    while(wei>0)
    {
        int at=num / pow(10,wei-1);
        ((NumOne*)nums->objectAtIndex(nums->count()-wei))->gotoAndStop(at+1);
        num =num % (int)pow(10,wei-1);
        wei--;
    }
    return num;
}
NumX::NumX (float x1,float y1,int n)
{
    this->setPosition(ccp(x1,y1));
    NumOne * firstNum = new NumOne();    firstNum->autorelease();addChild(firstNum);
    nums=new CCArray();
    nums->addObject(firstNum);
    for(int i=1;i<n;i++)
    {
        NumOne *secondNum = new NumOne();    secondNum->autorelease();
        NumOne *beforeNum=(NumOne*)nums->objectAtIndex(i-1);
        secondNum->setPosition(ccp(beforeNum->getPosition().x+beforeNum->getContentSize().width,0));
        addChild(secondNum);
        nums->addObject(secondNum);
    }
    
    draw(0);
}
NumX::~NumX()
{
    nums->release();
}



